#!/usr/bin/make -f

#compiler
CC=gcc

#release CFLAGS.
CFLAGS=-fPIC -Wall -pedantic --std=c99

#debug CFLAGS
DBGFLAGS=-fPIC -ggdb -Wall -pedantic --std=c99

#library target
TARGET=bin/libshredder.so.1.0.1

#include file
HEADER=include/shredder.h

#linker flags
LDFLAGS=-shared -Wl,-soname,libshredder.so.1 -o $(TARGET)

#list of all object files to build.
OBJECTS=\
src/util/file.o\
src/util/data.o\
src/util/folder.o\
src/shred/shred.o\


######################################################
#change this target to release when we want to release.
all: debug
######################################################


#set CFLAGS to debug CFLAGS for debug builds
debug: CFLAGS = $(DBGFLAGS)
#build objects automatically.
debug: $(OBJECTS)
	#link library.
	$(CC) $(OBJECTS) $(LDFLAGS)
	
#build release objects automatically
release: $(OBJECTS)
	#link library
	$(CC) $(OBJECTS) $(LDFLAGS)
	
#cleanup built objects for fresh build
clean: 
	rm -f $(OBJECTS) bin/*

#install project.
install: all
	if [ `id -u` != "0" ]; then echo "You need to be root to perform this task!"; exit 1; fi;
	
	install --mode=555 $(TARGET) $(DESTDIR)/usr/lib/
	install --mode=444 $(HEADER) $(DESTDIR)/usr/include/
	ln -sf $(DESTDIR)/usr/lib/libshredder.so.1 $(DESTDIR)/usr/lib/libshredder.so
	ldconfig

#remove project
uninstall:
	if [ `id -u` != "0" ]; then echo "You need to be root to perform this task!"; exit 1; fi;
	
	rm -f $(DESTDIR)/usr/lib/$(TARGET)
	rm -f $(DESTDIR)/usr/lib/libshredder.so
	ldconfig
	
#clean and uninstall are phony (i.e. no deps) targets.
.PHONY: clean uninstall
